

class forwarding_proxy(object):
    def __init__(self, real_object):
        self._real_object = real_object

    def set_object(self, real_object):
        self._real_object = real_object

    def __getattr__(self, attr):
        return on_demand_caller(self)


class on_demand_caller(object):
    def __init__(self, proxy):
        self._proxy = proxy

    def __call__(self, *args, **kwargs):
        return getattr(self._proxy._real_object,
                       self._proxy._attr)(*args, **kwargs)
